<?php include("session.php") ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0041)http://www.ewebvn.com/demo/div-three-col/ -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Wedding studio</title>
</head>
<body>
<?php 
    include("header_admin.php");
    require_once("../ketnoi_csdl.php");
?>
<?php
    $issuccess = true;
    if(isset( $_POST['submit'])){
        $path = "../../upload/albumcuoi/".$_POST['dir'];
		if (isset($_POST['albumdep'])) {
            $ischecked = true;
        }else {
            $ischecked = false;
        }
        if (!file_exists($path)) {
            $queryPlans = mysql_query("SELECT CONVERT(ID_ALBUM, SIGNED) as id FROM album ORDER BY ID_ALBUM DESC LIMIT 1");
            $row = mysql_fetch_array($queryPlans);
            $id = $row[0]+1;
			if($ischecked){
                $sql="INSERT INTO album VALUES('$id','$_POST[albumname]','$_POST[dir]','$_POST[url]','$_POST[des]',NOW(),'$ischecked')";    
            }else{
                $sql="INSERT INTO album VALUES('$id','$_POST[albumname]','$_POST[dir]','$_POST[url]','$_POST[des]',NOW(),DEFAULT)";
            }
            $success = mysql_query($sql,$con);
            if($success){
                mkdir($path, 0777, true);
                echo "<script type='text/javascript'>window.alert('Thêm album thành công')</script>";
            }else{
                echo "<script type='text/javascript'>window.alert('Thêm album không thành công')</script>";
            }
        }else{
            $issuccess = false;
             echo "<script type='text/javascript'>window.alert('Thư mục đã tồn tại')</script>";
        }
        
    }
?>

<div id="mainWap">
  <form action="" method="post">
    <table border="1" width="400" cellspacing="1" style="border-collapse: collapse" bordercolor="#C0C0C0">
        <tr>
            <td>Tên album:</td>
            <td><input type="text" name="albumname" value="<?php if(!$issuccess){
                if(isset($_POST['albumname'])){
                    echo $_POST['albumname'];
                }
            }?>"/></td>
        </tr>
        <tr>
            <td>Tên Thư Mục:</td>
            <td><input type="text" name="dir" value="<?php if(!$issuccess){
                if(isset($_POST['dir'])){
                    echo $_POST['dir'];
                }
            }?>"/></td>
        </tr>
        <tr>
            <td>Đường dẫn album:</td>
            <td><input type="text" name="url" value="<?php if(!$issuccess){
                if(isset($_POST['url'])){
                    echo $_POST['url'];
                }
            }?>"/></td>
        </tr>
        <tr>
            <td>Mô tả về album:</td>
            <td><input type="text" name="des" value="<?php if(!$issuccess){
                if(isset($_POST['des'])){
                    echo $_POST['des'];
                }
            }?>"/></td>
        </tr>
		<tr>
            <td>Chọn làm album đẹp:</td>
            <td><input type="checkbox" name="albumdep"/></td>
        </tr>
        <tr>
            <td><input type="submit" name="submit" value="Tạo Album"/></td>
        </tr>
    </table>
</form>
</div>

<?php include("footer_admin.php"); ?>
    <!-- end wapper -->

<div style="display:none" id="addthis-extension-script"></div></body><div style="display: none; " id="k1XKb07LtFf3qXDHOv7u5v1C" class="kzlzuwUwKPAvDYR3E7uqB8"></div><div style="display: none; " id="YV8CLCODDDq0pfWQ4qijEZEt_" class="kzlzuwUwKPAvDYR3E7uqB8"></div><div style="display: none; " id="kWRY8_3uCTQWbN_sjCoSQjlEqp" class="kzlzuwUwKPAvDYR3E7uqB8"></div></html>